package com.grouppurchase.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.grouppurchase.entity.Product;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ProductMapper extends BaseMapper<Product> {
    
    IPage<Product> selectProductPage(Page<Product> page, @Param("categoryId") Long categoryId, @Param("status") Integer status);
    
    @Select("SELECT * FROM products WHERE status = 1 ORDER BY sort_order DESC, created_at DESC")
    List<Product> selectActiveProducts();
    
    int updateStock(@Param("productId") Long productId, @Param("quantity") Integer quantity);
    
    int updateLockStock(@Param("productId") Long productId, @Param("quantity") Integer quantity);
}
